/*************************************************************************
	> File Name: client.cc
	> Author: H.M. Lau
	> Mail: hm.lau@outlook.com
	> Created Time: 2023/10/24 16:26
 ************************************************************************/

#include "Sock.hpp"

static void Usage(const std::string& proc)
{
    std::cout << "\nUsage:" << proc << " ip port" << std::endl;
}

int main(int argc, char *argv[])
{
    if (argc != 3) {
        Usage(argv[0]);
        exit(2);
    }
    std::string ip = argv[1];
    uint16_t port = atoi(argv[2]);
    Sock sock(port, ip);
    if (!sock.Connect()) {
        std::cout << "Connect error" << std::endl;
        exit(3);
    }
    std::string message;
    std::string recv;
    while (1) {
        std::cout << "Please input your message# ";
        std::getline(std::cin, message);
        sock.Send(message);
        if (!sock.Recv(recv)) {
            std::cout << "Client read error" << std::endl;
            exit(5);
        }
        std::cout << recv << std::endl;
    }
    return 0;
}

